﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ObjectDirectory;

namespace t_ObjectDirectory
{
    [TestClass]
    public class t_ObjectPathMangerTwoLevels
    {
        public class Sub1
        {
            public int joe;
        }

        public class Sub2
        {
            public Sub1 george { get; set; }
        }

        public class Container
        {
            public Sub2 stuff { get; set; }
        }

        [TestMethod]
        public void TestTwoLevelLookup()
        {
            Container c = new Container();
            c.stuff = new Sub2();
            c.stuff.george = new Sub1() { joe = 5 };

            ObjectPathManager mgr = new ObjectPathManager();

            Assert.AreEqual("stuff/george", mgr.GetPath(c, c.stuff.george), "Couldn't find 2nd level simple path");
        }

        [TestMethod]
        public void FindTwoLevelPath()
        {
            Container c = new Container();
            c.stuff = new Sub2();
            c.stuff.george = new Sub1() { joe = 5 };

            ObjectPathManager mgr = new ObjectPathManager();
            Assert.AreEqual(c.stuff.george, mgr.FindObjectFromPath(c, "stuff/george"), "Couldn't get back the correct object");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestGetPathTwoLevelsWithNull()
        {
            Container c = new Container();
            c.stuff = null;

            ObjectPathManager mgr = new ObjectPathManager();
            mgr.FindObjectFromPath(c, "stuff/george");
        }
    }
}